<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        var num = 10;

        function fn() {
            console.log(num);
            var num = 20;
            console.log(num);
        }
        fn();

        //相当于执行了下面的代码
        /*var num;        //提升变量

        function fn() {       //提升函数
            var num;   //函数内部变量提升
            console.log(num);   //就近原则，上面的num没有赋值，所以是undefined
            num = 20;
            console.log(num);  //就近原则，值是20
        }
        num=10;
        fn() */

    </script>
</head>

<body>

</body>

</html>